##=============================================================================
## Appendix Figure 15
##=============================================================================

##-----------------
# clear environment
rm(list=ls())
options(stringsAsFactors = FALSE, scipen = 999)
# source("R/functions.R")

seed <- sample.int(.Machine$integer.max, 1)
set.seed(seed)

ipak <- function(pkg){new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if(length(new.pkg)) install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}

packages <- c("tidyverse", "hrbrthemes")

ipak(packages)

##---------
# Load data
#setwd("/Users/austinknuppe/Library/CloudStorage/Dropbox/Ukraine2022WartimeSurvey/Paper_peace/final_version_oct_2024/replication-scripts")
load("clean_ukraine_data.RData")

plot <- dat %>% 
  drop_na(rus_lang_schools) %>% 
  mutate(wave = case_when(
    wave == 0 ~ "July 2022 \n n = 1,890",
    wave == 1 ~ "February 2023 \n n = 1,908")) %>%
  mutate(wave = factor(wave, levels = c("July 2022 \n n = 1,890", 
                                        "February 2023 \n n = 1,908"))) %>% 
  group_by(wave, rus_lang_schools) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% 
  mutate(rus_lang_schools = case_when(
    rus_lang_schools == 0 ~ "No",
    rus_lang_schools == 1 ~ "Yes")) %>% 
  mutate(rus_lang_schools = factor(rus_lang_schools, levels = c("No", "Yes")))

ggplot(plot, aes(x = wave, y = freq, fill = rus_lang_schools)) + 
  geom_bar(stat = "identity", position = position_dodge()) +
  labs(x = "", y = "Proportion", fill = "") +
  scale_y_continuous(labels = scales::percent) +
  scale_fill_grey() +
  theme_bw(base_size = 20) +
  theme(legend.position = "bottom", 
        legend.direction = "horizontal",
        legend.text = element_text(size = 20))

rm(list = ls())
##=============================================================================
## End of File
##=============================================================================